/*
 * HessenbergQR.cpp
 *
 *  Created on: 2014-7-13
 *      Author: cpp
 */

#include "HessenbergQR.h"
#include "Givens.h"
#include "Error.h"
Matrix* HessenbergQR::decom(Matrix& A) {
	if(!A.isHessenberg()||!A.isSquare()){
		throw SYSTEM_NOT_SUPPORT;
	}
	Matrix* result = A.clone();
	for(int j=0;j<result->getColL()-1;j++){
		double c=0;
		double s=0;
		Givens::givens(result->get(j,j),result->get(j+1,j),c,s);
		for(int k=j;k<result->getColL();k++){
			double tmp1 = result->get(j,k);
			double tmp2 = result->get(j+1,k);
			result->set(j,k,c*tmp1-s*tmp2);
			result->set(j+1,k,s*tmp1+c*tmp2);
		}
		struct cs ccs;
		ccs.c = c;
		ccs.s = s;
		css.push_back(ccs);
	}
	return result;
}
